package com.hsck.order.kds.setup.adapter

import android.view.View
import androidx.annotation.LayoutRes
import com.hsck.order.kds.R
import com.hsck.order.kds.base.bean.CategoryBean
import com.hsck.order.kds.base.bean.SetupBean
import com.hsck.order.kds.base.common.BaseAdapter
import com.hsck.order.kds.base.common.BaseViewHolder
import com.hsck.order.kds.base.common.setOnSingleClickListener
import com.hsck.order.kds.base.utils.LogUtil
import kotlinx.android.synthetic.main.item_yyts.view.*

/**
 * 语音提示-适配器
 */
class YytsAdapter(@LayoutRes layoutId: Int) : BaseAdapter<SetupBean>(layoutId) {

    var onPositionClick: ((SetupBean, Int) -> Unit) = { showBean, index -> }
    var onNumClick: ((SetupBean, Int) -> Unit) = { showBean, index -> }

    override fun onBindViewHolder(holder: BaseViewHolder, data: SetupBean) {
        holder.itemView.tv_item_yyts_cishu.text = "${data.code}"
        holder.itemView.cb_item_yyts.isChecked = data.isSelected
        if (data.isSelected){
            holder.itemView.lin_item_yyts_cishu.visibility=View.VISIBLE
        }else{
            holder.itemView.lin_item_yyts_cishu.visibility=View.GONE
        }

        holder.itemView.cb_item_yyts.setOnSingleClickListener {
            try {
                onPositionClick.invoke(data, holder.adapterPosition)
            } catch (e: Exception) {
                LogUtil.e("error" + e.message)
            }
        }
        holder.itemView.tv_item_yyts_cishu.setOnSingleClickListener {
            try {
                onNumClick.invoke(data, holder.adapterPosition)
            } catch (e: Exception) {
                LogUtil.e("error" + e.message)
            }
        }
    }
}